package com.example.servicea.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.plugins.Page;
import com.example.servicea.dao.LogMapper;
import com.example.servicea.entity.LogEntity;
import com.example.servicea.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * @Author generator.
 * @Date: 2017/10/26 10:58
 */
@Service("logServiceImpl")
public class LogServiceImpl implements LogService {
	@Autowired
	private LogMapper logMapper;
    @Override
    public boolean insert(LogEntity obj){
        return SqlHelper.retBool(logMapper.insert(obj));
    }
    @Override
    public List<LogEntity> selectList(LogEntity log){
        EntityWrapper<LogEntity> query = new EntityWrapper<LogEntity>();
		return logMapper.selectList(query);
	}

    @Override
    public Page selectPage(LogEntity log, String page, String limit){
        EntityWrapper<LogEntity> query = new EntityWrapper<LogEntity>();
        List<LogEntity> list = logMapper.selectPage(
                new Page<LogEntity>(Integer.parseInt(page),Integer.parseInt(limit)),
                query);
        int total = logMapper.selectCount(query);
        Page logEntityPage = new Page();
        return logEntityPage;
	}
    @Override
    public int selectCount(LogEntity log){
        EntityWrapper<LogEntity> query = new EntityWrapper<LogEntity>();
        return logMapper.selectCount(query);
	}

    @Override
    public LogEntity selectOne(LogEntity log){
        return logMapper.selectOne(new LogEntity());
	}

    @Override
    public LogEntity selectById(String id){
        return logMapper.selectById(id);
	}

	@Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateById(LogEntity log){
        return SqlHelper.retBool(logMapper.updateById(log));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(String id){
        return SqlHelper.retBool(logMapper.deleteById(Integer.parseInt(id)));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatchIds(String ids){
        String[] s = ids.split(",");
        List<String> list = Arrays.asList(s);
        return SqlHelper.retBool(logMapper.deleteBatchIds(list));
	}
	
}
